// 翻滚加载(热搜部分)
// 思路;向下翻滚，页数加一，请求发送一次，渲染一次
var currentPage = 1;
// 判断数据是否为0
function judge(data) {
  if (data.transmit == 0) {
    data.transmit = "分享";
  }
  if (data.likes == 0) {
    data.likes = "点赞";
  }
  if (data.comment == 0) {
    data.comment = "评论";
  }
}
let label = getUrlParam(1);
console.log(label);
function getrestMsg() {
  $(window).scroll(function () {
    if (
      Math.round($(window).scrollTop() + $(window).height()) ==
      $(document).height()
    ) {
      currentPage++;
      $.ajax({
        url: `/weibo/blog/skipToLoadedBlog?label=${label}&pageNo=${currentPage}&pageSize=10`,
        type: "get",
        data: {},
        success: function (result) {
          console.log(result);
          let allnews = document.querySelector(".allnews");
          console.log("请求发送");
          console.log(result.length);
          for (let i = 0; i < result.length; i++) {
            judge(result[i]);
            allnews.innerHTML += `<div class="news add" uid="${result[i].uid}" bid="${result[i].id}">
          <div class="news-top">
            <a href="/user/toOnesInfo?id=${result[i].uid}" class="head-link">
              <div class="head">
                <img
                        src="${result[i].userAvatarUrl}"
                        alt=""
                />
              </div>
            </a>
            <div class="top-details">
              <a href="" class="name">
                <p >${result[i].username}</p>
              </a>
              <p class="time">${result[i].time}</p>
            </div>
            <div class="top-attention">
              <button class="top-attention-btn">
                <i class="iconfont">&#xe7df;</i>关注
              </button>
            </div>
            <div class="report-remove">
            <div class="rm-icon" bid="${result[i].id}" otherid="${result[i].uid}" onclick="reportfn(this)">
              <i class="iconfont">&#xe62e;</i>
            </div>
            <ul class="rm-detials hidden">
              <li class="tip-off-li" bid="${result[i].id}" onclick="tipOffFn(this)">
                投诉
              </li>
              <li class="remove-li" bid="${result[i].id}" onclick="removeBlog(this)">
                删除
              </li>
            </ul>
          </div>
          </div>
          <div class="news-container">
            <div  class="container">
            <a class="color" href="/blog/skipToBlog?label=${result[i].label}">#${result[i].label}#</a>&nbsp;&nbsp;
            <span class="container-text" >${result[i].text}</span>

              <span class="collapse">收起</span>
            </div>

            <div class="news-content">
            </div>
          </div>
          <!-- 底部博文功能 -->
          <div class="foot">
            <div class="share">
              <i class="iconfont">&#xe62f;</i>
              <span>${result[i].transmit}</span>
            </div>
            <div class="assess" bid="${result[i].id}">
              <i class="iconfont">&#xe695;</i>
              <span>${result[i].comment}</span>
            </div>
            <div class="store">
            <i class="iconfont">&#xe647;</i>
            <span>收藏</span>
          </div>
            <div class="like">
              <i class="iconfont">&#xe62b;</i>
              <span>${result[i].likes}</span>
            </div>
          </div>
          <!-- 点击评论展开评论信息 -->
          <div class="spread">
            <textarea
                    placeholder="请发布你的评论"
                    class="comment-text"
            ></textarea>
            <span class="comment-ddl">还可输入140字</span>
            <button class="comment-btn disable" bid="${result[i].id}">评论</button>
            <!-- 评论 -->
            <div class="comment">   
            </div>
          </div>
        </div>`;
            let add = document.getElementsByClassName("add")[i];
            let content = add.querySelector(".news-content");
            let picture = result[i].pictureUrl;
            if (picture.length > 0) {
              for (let j = 0; j < picture.length; j++) {
                content.innerHTML += `<div class="news-content-img"  >
          <img src="${picture[j]}"alt="" onclick="showModel(this)">
        </div>`;
              }
            }
          }
          if (result.length >= 0 && result.length < 10) {
            document.querySelector(".none").classList.remove("hidden");
          }
          more();
          assessBtn();
          commentfn();
          YesOrNo();
          func();
          replyWindow();
          collapsefn();
          switchovefn();
          reportfn();
        },
      });
    }
  });
}
getrestMsg();
